package com.assessment.mapper;

import com.assessment.model.entity.AssessmentResult;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 评分结果Mapper接口
 */
public interface AssessmentResultMapper extends BaseMapper<AssessmentResult> {

    /**
     * 查询部门内教师在周期的评测结果
     */
    @Select("SELECT * FROM t_assessment_result " +
            "WHERE department_id = #{departmentId} AND period_id = #{periodId} AND category_id IS NULL " +
            "ORDER BY avg_score DESC")
    List<AssessmentResult> findByDepartmentAndPeriod(@Param("departmentId") Integer departmentId,
                                                     @Param("periodId") Integer periodId);

    /**
     * 查询教师在周期各类别的评测结果
     */
    @Select("SELECT * FROM t_assessment_result " +
            "WHERE teacher_id = #{teacherId} AND period_id = #{periodId} AND category_id IS NOT NULL " +
            "ORDER BY category_id")
    List<AssessmentResult> findTeacherCategoryResults(@Param("teacherId") Integer teacherId,
                                                      @Param("periodId") Integer periodId);

    /**
     * 查询教师在周期的总体评测结果
     */
    @Select("SELECT * FROM t_assessment_result " +
            "WHERE teacher_id = #{teacherId} AND period_id = #{periodId} AND category_id IS NULL " +
            "LIMIT 1")
    AssessmentResult findTeacherOverallResult(@Param("teacherId") Integer teacherId,
                                              @Param("periodId") Integer periodId);
}
